#include "common.hpp"

int main()
{

    
    // 创建共享内存
    key_t key = ftok(pathname, proj_id);
    int shmid = shmget(key, 4096, IPC_CREAT|IPC_EXCL|0666);
    if (shmid == -1)
    {
        perror("shmget");
        exit(1);
    }

    // 关联起来
    char *shmaddr = (char *)shmat(shmid, nullptr, 0);

    // 进行通信
    while(true)
    {
        std::cout << "clien send:" << shmaddr << std::endl;  
        sleep(1);
    }


    // 释放关联
    int ret = shmdt(shmaddr);
    if(ret == -1)
    {
        perror("shmdt");
        exit(3);
    }

    // 释放共享内存
    ret = shmctl(shmid, IPC_RMID, nullptr);
    if(ret == -1)
    {
        perror("shmctl");
        exit(4);
    }
    return 0;
}